package com.spark.gaea.quartz.utils;

import com.spark.gaea.utils.DateUtil;
import com.spark.gaea.utils.ID;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.quartz.TriggerListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;

public class MonitorTriggerListener implements TriggerListener {
	private static final Logger logger;

	@Override
	public String getName() {
		return "MonitorTriggerListener";
	}

	@Override
	public void triggerFired(final Trigger trigger, final JobExecutionContext context) {
	}

	@Override
	public boolean vetoJobExecution(final Trigger trigger, final JobExecutionContext context) {
		return false;
	}

	@Override
	public void triggerMisfired(final Trigger trigger) {
	}

	@Override
	public void triggerComplete(final Trigger trigger, final JobExecutionContext context, final Trigger.CompletedExecutionInstruction triggerInstructionCode) {
		final StringBuffer sb = new StringBuffer();
		sb.append("\u89e6\u53d1\u65f6\u95f4\uff1a").append(DateUtil.format(context.getFireTime()));
		sb.append("\uff0c");
		sb.append("\u7528\u65f6\uff1a").append(context.getJobRunTime()).append("\u6beb\u79d2");
		sb.append("\uff0c");
		sb.append("\u4e0b\u6b21\u89e6\u53d1\uff1a").append(DateUtil.format(context.getNextFireTime()));
		sb.append("\u3002");
		final HashMap params = new HashMap();
		params.put("id", ID.getNativeUUID());
		params.put("job_id", context.getJobDetail().getKey());
		params.put("type", "\u6267\u884c");
		params.put("log", sb);
		params.put("created", DateUtil.getTime());
	}

	static {
		logger = LoggerFactory.getLogger(MonitorTriggerListener.class);
	}
}
